package rickyGame.game.action
{
	import ricky.game.Actor;
	import ricky.game.action.Act2D;
	import ricky.game.graphic.Graphic;
	import ricky.utils.FrameManager;
	import ricky.utils.TimeServer;
	
	import ricky.game.Actor2D;
	import rickyGame.game.GameState;
	import rickyGame.game.action.ActionHelper;
	
	public class DeathAct extends Act2D
	{
		/**
		 * actor:Actor 受伤对象
		 * deadTime:Number 尸体持续时间
		 * par:Number;伤害值
		 */
		public function DeathAct(actor:Actor,deadTime:Number=5000)
		{
			super(actor);
			this._animProperty= "death";
			_endTime=deadTime;
		}
		
		override public function begin():void
		{
			actor.isDead=true;
			super.begin();
			FrameManager.inst.addLogic(this);
			_startTime=TimeServer.now();
			_endTime=_startTime+_endTime;
			_alphaTime=_startTime+3000;
		}
		
		override public	function action(timeline:Number):void
		{
			if(_state<1) //如果没有初始化
				return;

			if(timeline>_alphaTime )
			{
				if(timeline % 500==0)
					Graphic(actor.graphic).alpha=0.5;
				else
					Graphic(actor.graphic).alpha=1;
			}
			if(timeline>=_endTime)
			{
				GameState.inst.sceneManager.killGameObject(Actor2D(actor));
				this.complete();
			}
		}
		
		override public function end():void
		{
			if(this._effectNext)
				ActionHelper.inst.addAct(_effectNext);
			
			FrameManager.inst.removeLogic(this);

			super.end();
		}
		
		override public function dispose():void
		{
			_endTime=0;
			super.dispose();
		}
		
		
		//private ************************************************
		private var _startTime:Number;//开始时间毫秒数
		private var _endTime:Number;//持续时间毫秒数
		private var _alphaTime:Number;
	}
}